package org.example.wx_springboot.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.wx_springboot.common.Result;

import org.example.wx_springboot.entity.Shoppingcart;
import org.example.wx_springboot.service.IShoppingcartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin//这个注解是解决跨域错误的
@RestController
@Slf4j
@RequestMapping("/shoppingcart")
public class ShoppingcartConttroller {

    @Autowired
    IShoppingcartService shoppingcartService;


    @GetMapping("/cart")
    public Result list(){
        List<Shoppingcart> shoppingcart = shoppingcartService.list();
        return Result.success(shoppingcart);//返回CommodityMapper的数据
    }


    @PostMapping("/seve")
    public Result save(@RequestBody Shoppingcart shoppingcart){
        shoppingcartService.save(shoppingcart);
        return Result.success();
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Integer id){
        shoppingcartService.deleteById(id);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Shoppingcart obj){
        shoppingcartService.update(obj);
        return Result.success();
    }



}
